/*******************************************************************************
   @file   cmdline.h
   @author  H.M.Shim (elecage@gmail.com)
   @version
   @date    2013. 7. 25.
   @brief
  ******************************************************************************
  The MIT License (MIT)

Copyright (c) 2013 <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  ******************************************************************************
  */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef CMDLINE_H_
#define CMDLINE_H_

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Exported typdef -----------------------------------------------------------*/
/** Command line function callback type */
typedef int32_t (*CmdLineFunc)(int32_t argc, int8_t *argv[]);
/**
 * @struct COMMAND_LINE_ENTRY
 * @brief 명령어를 등록해놓는 구조체
 */
typedef struct {
	const int8_t 	*cmd;				/**< 명령어 문자열을 등록한다 */
	CmdLineFunc		callback;			/**< 해당 명령에 대한 콜백함수를 등록한다. */
	const int8_t	*help;				/**< Help 문장을 등록한다. */
}COMMAND_LINE_ENTRY;

/* Exported constants --------------------------------------------------------*/
#define CMDLINE_BAD_CMD			(-1)	/**< 등록하지 않거나 문법에 맞지 않는 명령어가 입력되었을 때 리턴*/
#define CMDLINE_TOO_MANY_ARGS	(-2)	/**< 해당 명령어에서 너무 많은 인자가 입력되었을 때 리턴 */
#define CMDLINE_TOO_FEW_ARGS	(-3)	/**< 해당 명령어에서 너무 적은 인자가 입력되었을 때 리턴 */
#define CMDLINE_INVALID_ARGS	(-4)	/**< 인자가 적정하지 않을 때 리턴 */
#define MAX_CMDLINE_SIZE		32
/* Exported macro ------------------------------------------------------------*/

/* Exported variables ------------------------------------------------------- */
extern COMMAND_LINE_ENTRY cmdTable[];	/**< 명령어를 배열로 구성 */
/* Exported functions ------------------------------------------------------- */
extern int32_t cmdLineProcess(int8_t *cmdLine);
extern int32_t registerCmdline(const int8_t *cmd, CmdLineFunc callback, const int8_t *help);
extern int32_t cmdHelp(int32_t argc, int8_t *argv[]);
/* Private function prototypes -----------------------------------------------*/

#endif /* CMDLINE_H_ */
